package cn.elwy.rcp.ui.explorer.core.model;

import com.yss.sofa.common.util.ConvertTypeUtil;
import com.yss.sofa.common.util.AssertUtil;

public class TargetColumnType {

  private String type;
  private Integer length;
  private Integer precision;
  private Integer scale;
  private String lengthText;
  private String precisionText;
  private String scaleText;
  private Boolean isNullLength;

  /**
   * @return the isNullLength
   */
  public Boolean getIsNullLength() {

    return isNullLength;
  }

  /**
   * @param isNullLength the isNullLength to set
   */
  public void setIsNullLength(Boolean isNullLength) {

    this.isNullLength = isNullLength;
  }

  /**
   * @return the isNullPrecision
   */
  public Boolean getIsNullPrecision() {

    return isNullPrecision;
  }

  /**
   * @param isNullPrecision the isNullPrecision to set
   */
  public void setIsNullPrecision(Boolean isNullPrecision) {

    this.isNullPrecision = isNullPrecision;
  }

  /**
   * @return the isNullScale
   */
  public Boolean getIsNullScale() {

    return isNullScale;
  }

  /**
   * @param isNullScale the isNullScale to set
   */
  public void setIsNullScale(Boolean isNullScale) {

    this.isNullScale = isNullScale;
  }

  private Boolean isNullPrecision;
  private Boolean isNullScale;

  public TargetColumnType() {

  }

  public TargetColumnType(String type, String lengthText, String precisionText, String scaleText) {
    this.type = type;
    this.lengthText = lengthText;
    this.precisionText = precisionText;
    this.scaleText = scaleText;
    initTargetColumnType(lengthText, precisionText, scaleText);
  }

  private void initTargetColumnType(String length, String precision, String scale) {
    if (AssertUtil.isNotEmpty(length)) {
      if (!"l".equalsIgnoreCase(length)) {
        setLength(ConvertTypeUtil.toInteger(length, null));
      }
      setIsNullLength(false);
    } else {
      setIsNullLength(true);
    }

    if (AssertUtil.isNotEmpty(precision)) {
      if (!"p".equalsIgnoreCase(precision)) {
        setPrecision(ConvertTypeUtil.toInteger(precision, null));
      }
      setIsNullPrecision(false);
    } else {
      setIsNullPrecision(true);
    }

    if (AssertUtil.isNotEmpty(scale)) {
      if (!"s".equalsIgnoreCase(scale)) {
        setScale(ConvertTypeUtil.toInteger(scale, null));
      }
      setIsNullScale(false);
    } else {
      setIsNullScale(true);
    }
  }

  /**
   * @return the type
   */
  public String getType() {
    return type;
  }

  /**
   * @param type the type to set
   */
  public void setType(String type) {
    this.type = type;
  }

  /**
   * @return the length
   */
  public Integer getLength() {
    return length;
  }

  /**
   * @param length the length to set
   */
  public void setLength(Integer length) {
    this.length = length;
  }

  /**
   * @return the precision
   */
  public Integer getPrecision() {
    return precision;
  }

  /**
   * @param precision the precision to set
   */
  public void setPrecision(Integer precision) {
    this.precision = precision;
  }

  /**
   * @return the scale
   */
  public Integer getScale() {
    return scale;
  }

  /**
   * @param scale the scale to set
   */
  public void setScale(Integer scale) {
    this.scale = scale;
  }

  /**
   * @return the lengthText
   */
  public String getLengthText() {
    return lengthText;
  }

  /**
   * @param lengthText the lengthText to set
   */
  public void setLengthText(String lengthText) {
    this.lengthText = lengthText;
  }

  /**
   * @return the precisionText
   */
  public String getPrecisionText() {
    return precisionText;
  }

  /**
   * @param precisionText the precisionText to set
   */
  public void setPrecisionText(String precisionText) {
    this.precisionText = precisionText;
  }

  /**
   * @return the scaleText
   */
  public String getScaleText() {
    return scaleText;
  }

  /**
   * @param scaleText the scaleText to set
   */
  public void setScaleText(String scaleText) {
    this.scaleText = scaleText;
  }

}
